/*
 *  Netzpult - Your desk on the web
 *  Copyright (C) 2011  Ulrich Hilger, http://uhilger.de
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/
 */

package de.uhilger.netzpult.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;

/**
 * Superklasse für alle Elemente der Bedienoberfläche
 * 
 * @author Copyright (c) Ulrich Hilger, http://uhilger.de
 * @author Published under the terms and conditions of
 * the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
 */
public abstract class AbstrakteGestalt extends Composite implements Gestalt {
	

	public void fehlermeldung(Throwable caught) {
		Window.alert(gestaltName[getGestalt()] + " Fehler im Serveraufruf: " + caught.getMessage());
	}
	
	public void fehlermeldung(Request request, Throwable exception) {
		Window.alert(gestaltName[getGestalt()] + " Fehler im Serveraufruf: " + request.toString() + 
				", Server meldet " + exception.getMessage());
	}
	
	/**
	 * Aus der gegenwärtigen Fenster-URL 
	 * den URL ohne Pfad und ohne '/' am Ende ermitteln
	 * 
	 * <p>
	 * Aus http://dev.uhilger.de/ablage wird http://dev.uhilger.de<br>
	 * aus http://dev.uhilger.de/seiten/ulrich/14 wird http://dev.uhilger.de
	 * </p>
	 * 
	 * @return  den URL ohne Pfad und ohne '/' am Ende
	 */
	protected String getBaseUrl() {
		String base = Window.Location.getHref();
		//GWT.log("href=" + base);
		int pos = base.indexOf(Window.Location.getPath());
		if(pos > -1) {
			base = base.substring(0, pos);
		}
		//GWT.log("base=" + base);
		return base;
	}
	
}
